package com.exam.system.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author LY
 * @create 2023/10/7 17:31
 * @Description 测试security权限
 *
 */
@RestController
@RequestMapping("test2")
public class TestController2 {

    @PreAuthorize("hasAuthority('ADMIN')")
    @GetMapping("/getStr")
    public String getStr(){
        return "getStr";
    }

    @PreAuthorize("hasAuthority('ADMIN2')")
    @GetMapping("/getStr1")
    public String getStr1(){
        return "getStr1";
    }

    @PreAuthorize("hasAnyAuthority('ADMIN','ADMIN2')")
    @GetMapping("/getStr2")
    public String getStr2(){
        return "getStr2";
    }

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @GetMapping("/getStr3")
    public String getStr3(){
        return "getStr3";
    }

    @PreAuthorize("hasRole('ROLE_ADMIN2')")
    @GetMapping("/getStr4")
    public String getStr4(){
        return "getStr4";
    }

    @PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_ADMIN2')")
    @GetMapping("/getStr5")
    public String getStr5(){
        return "getStr5";
    }
}
